#ifndef BASIC_HPP
#define BASIC_HPP

#include <QString>
#include <QStringList>
#include <QList>
#include <QMap>
#include <QDateTime>
#include <QDate>
#include <QUuid>
#include <QJsonObject>
#include <QJsonArray>
#include "Rhythm.hpp"
#include "LadderLine.hpp"

struct Basic;

Q_DECLARE_METATYPE(Basic)

struct Basic {
    QString id;
    QDateTime startTime;
    QDateTime endTime;
    QList<Rhythm> rhythms;
    QList<LadderLine> ladderLines;


    Basic(const QString& id,
          const QDateTime& startTime,
          const QDateTime& endTime,
          const QList<Rhythm>& rhythms,
          const QList<LadderLine>& ladderLines)
        : id(id),
          startTime(startTime),
          endTime(endTime),
          rhythms(rhythms),
          ladderLines(ladderLines)
    {}


    Basic(const QDateTime &startTime = QDateTime(QDate::currentDate()),
          const QDateTime &endTime = QDateTime(QDate::currentDate()))
        : Basic(QUuid::createUuid().toString(), startTime, endTime, QList<Rhythm>(), QList<LadderLine>())
    {}


    Basic(const QDateTime& startTime, const QDateTime& endTime, const QList<Rhythm>& rhythms, const QList<LadderLine>& ladderLines)
        : Basic(QUuid::createUuid().toString(), startTime, endTime, rhythms, ladderLines)
    {}


    Basic(const QDateTime& startTime, const QDateTime& endTime, const QList<Rhythm>& rhythms)
        : Basic(QUuid::createUuid().toString(), startTime, endTime, rhythms, QList<LadderLine>())
    {}


    Basic(const QDateTime& startTime, const QDateTime& endTime, const QList<LadderLine>& ladderLines)
        : Basic(QUuid::createUuid().toString(), startTime, endTime, QList<Rhythm>(), ladderLines)
    {}

    // Convert to JSON
    QJsonObject toJson() const {
        QJsonObject json;
        json["id"] = id;
        json["startTime"] = startTime.toString(Qt::ISODate);
        json["endTime"] = endTime.toString(Qt::ISODate);

        QJsonArray rhythmsArray;
        for (const Rhythm& rhythm : rhythms) {
            rhythmsArray.append(rhythm.toJson());
        }
        json["rhythms"] = rhythmsArray;

        QJsonArray ladderLineArray;
        for (const LadderLine& ladderLine : ladderLines) {
            ladderLineArray.append(ladderLine.toJson());
        }
        json["ladderLines"] = ladderLineArray;

        return json;
    }
};

#endif // BASIC_HPP